//记录查询条件用于回显
// var searchParamArr={"code":-1,"param":""};
function findAssets(CertusJsonAjax, CertusFormAjax, $scope) {
    //打开导入 excel
    $scope.importExcel = function () {
        $scope.bxType = "ZCGL";
        $("#fileUploadId").val("");
        //打开 上传页面
        $(".hidefile").show();
    }

    $scope.downloadModel = function () {
        CertusFormAjax.download("downloadModel", "type=" + "ZCGL");
    }

    $scope.bxType = "ZCGL";
    $scope.bxExcelImport = function () {
        if ($scope.bxType && !angular.isUndefined($scope.bxType)) {
            var form = new FormData();
            var file = document.getElementById("fileUploadId").files[0];
            if (!file) {
                return;
            }
            form.append('file', file);
            form.append("bxType", $scope.bxType);
            var tish = layer.load(1);
            CertusFormAjax.upload("bxExcelImport", form, function (res) {
                layer.close(tish);
                if (res.data.startsWith("success")) {
                    layer.msg("数据导入成功,成功导入" + res.data.replace("success--", "") + "条");
                    $(".hidefile").hide();
                    return;
                } else if (res.data.startsWith("failed")) {
                    layer.msg("第" + res.data.replace("failed", "") + "行，数据有问题");
                    $(".hidefile").hide();
                    return;
                }

                layer.msg(res.data);
            });
        }

    }

    function hidefile() {
        $(".hidefile").hide();
    }

    $scope.bxSelect = [
        { name: "资产", code: "ZCGL" }
    ];


    CertusFormAjax.ajax("isCrcd", {
        "code": "XMZCGL"
    }, function (response) {
        var data = JSON.parse(response.data);
        if (data.isTrue == true) {
            $scope.isCrud = true;
        } else {
            $scope.isCrud = false;
        }
        // 资产信息
        var assetsColumns = [{
            id: 'asset_id',
            title: '资产编号',
            width: 200,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'asset_style1',
            title: '资产类目',
            width: 80,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'asset_style2',
            title: '资产类别',
            width: 150,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'asset_status',
            title: '目前状态',
            width: 53,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                var status = record.asset_status;
                if (status == 0) {
                    content += "占用";
                } else if (status == 1) {
                    content += "维护";
                } else if (status == 2) {
                    content += "停用";
                } else if (status == 3) {
                    content += "报废";
                } else if (status == 4) {
                    content += "待入库";
                } else if (status == 5) {
                    content += "空闲";
                }
                return content;
            }
        }, {
            id: 'city_location',
            title: '放置地点',
            width: 73,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'user_name',
            title: '归属者',
            width: 73,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'pro_name',
            title: '归属项目',
            width: 100,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'asset_source',
            title: '来源方式',
            width: 53,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'asset_profile',
            title: '资产描述',
            type: 'string',
            columnClass: 'text-left',
        }, {
            id: 'operation',
            title: '操作',
            width: 130,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                content += '<button class="btn btn-xs btn-success" onclick="editast(\'' + record.asset_id + '\');"><i class="icon-exchange"></i>  办理</button>';
                content += ' ';
                if (data.isTrue) {
                    content += '<button class="btn btn-xs btn-info" onclick="raddast(\'' + record.asset_id + '\');"><i class="fa fa-edit"></i> 修改</button>';
                }
                return content;
            }
        }];
        this.search = function (code, param) {
            $("#assetsContainer").empty();
            $("#assetsToolBarContainer").empty();
            CertusJsonAjax.dataInit("findAssetsList", {
                "code": code,
                "param": param
            }, assetsColumns, 'assetsContainer', 'assetsToolBarContainer');
        }
        // search(searchParamArr.code, searchParamArr.param);
        //初始化查询

        var assetsCode = localStorage.getItem("assetsCode");
        if (assetsCode==null||assetsCode==undefined){
            assetsCode=0;
        }
        var assetsParam = localStorage.getItem("assetsParam");
        if ($scope.isCrud){
            search(0,"");
        }else{
            if (assetsCode == 0) {
                search(-1,"");
            } else {
                search(assetsCode, assetsParam);
            }
        }

        $("#searchCode").val(assetsCode);
        changeparam(assetsCode);
        setTimeout(function () {
            $("#searchParam").val(assetsParam);
        }, 100);

        $(".psearch").on('click', function () {
            // searchParamArr.code = code;
            // searchParamArr.param= param;
            var code = $("#searchCode").val();
            var param = $("#searchParam").val();
            localStorage.setItem("assetsCode", code);
            localStorage.setItem("assetsParam", param);
            search(code, param);
        });

    });

    this.changeparam = function (code) {
        var html = "";
        if (code == 0) {
            //全部
            html += '<input type="text" value="" id="searchParam" class="form-control"  style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;" disabled/>';
            $("#paramt").html(html);
        } else if (code == 1) {

            CertusFormAjax.ajax("isCrcd", {
                "code": "XMZCGL"
            }, function (response) {
                var data = JSON.parse(response.data);
                //归属公司
                CertusFormAjax.ajax("companyListByCode", { "code": data.comanyCode }, function (response) {
                    html += '<select id="searchParam" class="form-control" style="position: relative;margin-left:-4px;text-indent:4px;">';
                    html += '<option value="">请选择</option>';
                    var data = JSON.parse(response.data);
                    for (var i = 0; i < data.length; i++) {
                        html += '<option value="' + data[i].companyId + '">' + data[i].company + '</option>';
                    }
                    html += '</select>';
                    $("#paramt").html(html);
                });
            });
        } else if (code == 2) {
            //归属人
            CertusFormAjax.ajax("findSpUserList", {}, function (response) {
                var html1 = '<input type="text" value="" id="autocomplete" class="form-control" style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;"/>' +
                    '<input type="hidden" value="" id="searchParam" style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;"/>';
                $("#paramt").html(html1);
                var nhlTeams = [];
                var data = response.data;
                for (var i = 0; i < data.length; i++) {
                    var arr = {};
                    arr.name = data[i].userName + "[" + data[i].positonName + "]";
                    arr.id = data[i].userId;
                    nhlTeams.push(arr);
                }
                //自动补全
                var nhl = $.map(nhlTeams, function (obj) {
                    return {
                        value: obj.name,
                        data: {
                            category: obj.id
                        }
                    };
                });
                // Initialize autocomplete with local lookup:
                $('#autocomplete').devbridgeAutocomplete({
                    lookup: nhl,
                    minChars: 1,
                    onSelect: function (suggestion) {
                        $("#searchParam").val(suggestion.data.category);
                    },
                    showNoSuggestionNotice: true,
                    noSuggestionNotice: 'Sorry, no matching results'
                });
            });
        } else if (code == 3) {
            //归属项目
            CertusFormAjax.ajax("findSeProList", {}, function (response) {
                var html1 = '<input type="text" value="" id="autocomplete" class="form-control" style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;"/>' +
                    '<input type="hidden" value="" id="searchParam" style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;"/>';
                $("#paramt").html(html1);
                var nhlTeams = [];
                var data = response.data;
                for (var i = 0; i < data.length; i++) {
                    var arr = {};
                    arr.name = data[i].proName;
                    arr.id = data[i].id;
                    nhlTeams.push(arr);
                }
                //自动补全
                var nhl = $.map(nhlTeams, function (obj) {
                    return {
                        value: obj.name,
                        data: {
                            category: obj.id
                        }
                    };
                });
                // Initialize autocomplete with local lookup:
                $('#autocomplete').devbridgeAutocomplete({
                    lookup: nhl,
                    minChars: 1,
                    onSelect: function (suggestion) {
                        $("#searchParam").val(suggestion.data.category);
                    },
                    showNoSuggestionNotice: true,
                    noSuggestionNotice: 'Sorry, no matching results'
                });
            });
        } else if (code == 4) {
            //编号
            html += '<input type="text" value="" id="searchParam" class="form-control" style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;"/>';
            $("#paramt").html(html);
        } else if (code == 5) {
            //资产分类
            CertusFormAjax.ajax("findStyles", {}, function (response) {
                html += '<select id="searchParam" class="form-control" style="position: relative;margin-left:-4px;text-indent:4px;">';
                html += '<option value="">请选择</option>';
                var data = response.data;
                for (var i = 0; i < data.length; i++) {
                    html += '<option value="' + data[i].styleId + '">' + data[i].assetStyle2 + '</option>';
                }
                $("#paramt").html(html);
            });
        } else if (code == 7) {
            //归属人
            CertusFormAjax.ajax("findSpUserList", {}, function (response) {
                var html1 = '<input type="text" value="" id="autocomplete" class="form-control" style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;"/>' +
                    '<input type="hidden" value="" id="searchParam" style="border-bottom-left-radius: 0;border-top-left-radius: 0;border-bottom-right-radius: 4px;border-top-right-radius: 4px;"/>';
                $("#paramt").html(html1);
                var nhlTeams = [];
                var data = response.data;
                for (var i = 0; i < data.length; i++) {
                    var arr = {};
                    arr.name = data[i].userName + "[" + data[i].positonName + "]";
                    arr.id = data[i].userId;
                    nhlTeams.push(arr);
                }
                //自动补全
                var nhl = $.map(nhlTeams, function (obj) {
                    return {
                        value: obj.name,
                        data: {
                            category: obj.id
                        }
                    };
                });
                // Initialize autocomplete with local lookup:
                $('#autocomplete').devbridgeAutocomplete({
                    lookup: nhl,
                    minChars: 1,
                    onSelect: function (suggestion) {
                        $("#searchParam").val(suggestion.data.category);
                    },
                    showNoSuggestionNotice: true,
                    noSuggestionNotice: 'Sorry, no matching results'
                });
            });
        } else {
            //状态
            html += '<select id="searchParam" class="form-control" style="position: relative;margin-left:-4px;text-indent:4px;">';
            html += '<option value="">请选择</option>';
            html += '<option value="0">占用</option>';
            html += '<option value="1">维修</option>';
            html += '<option value="2">停用</option>';
            html += '<option value="3">报废</option>';
            html += '<option value="4">待入库</option>';
            html += '<option value="5">空闲</option>';
            $("#paramt").html(html);
        }
    }
}
//修改资产
function raddast(id) {
    var reg = new RegExp("#", "g");
    id = id.replace(reg, "-");
    location.href = "#/toRadAsset/" + id;
}

function toRadAssets(CertusFormAjax, $scope, $routeParams) {
    //所属公司
    CertusFormAjax.ajax("companyListByViewCode", {}, function (response) {
        $scope.comp = JSON.parse(response.data);
    });
    CertusFormAjax.ajax("findAssStyles", {}, function (response) {
        $scope.data = response.data;
    });
    CertusFormAjax.ajax("findStyles", {}, function (response) {
        $scope.sdata = response.data;
    });
    var assetId = $routeParams.id;
    var reg = new RegExp("-", "g");
    assetId = assetId.replace(reg, "#");
    CertusFormAjax.ajax("findAssetFileInfo", {
        "assId": assetId
    }, function (response) {
        var data = response.data;
        $scope.assetNo = data.asset_id;
        $scope.asId = data.id;
        if (data.pic_address != undefined) {
            var pic = data.pic_address.split("/");
            var picname = pic[pic.length - 1];
            var opic = picname.substr(14, picname.length);
            $scope.picAddress = opic;
        }
        $scope.companys = data.company_code;
        $scope.asname = data.asset_code;
        $scope.asname2 = data.style_id;
        $scope.assetSource = data.asset_source;
        $scope.cityLocation = data.city_location;
        $scope.buildingLocation = data.building_location;
        $scope.floorLocation = data.floor_location;
        $scope.roomLocation = data.room_location;
        $scope.areaLocation = data.area_location;
        $scope.assetProfile = data.asset_profile;
        $scope.comments = data.comments;
        $scope.createUser = data.createUser;
        $scope.createTime = data.create_time;
        $scope.purchasePrice = data.purchase_price;
        $scope.purchaseTime = data.purchaseTime;
        $scope.assetName = data.asset_name;
        $scope.snNo = data.sn_no;
    });

    $(".submit").on('click', function () {
        if (!certusValidateNotnull()) {
            return;
        }
        var form = new FormData();
        var file = document.getElementById("pic").files[0];
        if (file != undefined) {
            form.append('file', file);
            CertusFormAjax.upload("fileUploadImg", form, function (response) {
                var imdata = response.data;
                if (imdata.isUpload == true) {
                    var arr = $("form").serializeArray();
                    var data = {};
                    for (var i = 0; i < arr.length; i++) {
                        data[arr[i].name] = arr[i].value;
                    };
                    data.picAddress = imdata.path;
                    CertusFormAjax.ajax("toEditAsset", {
                        "param": JSON.stringify(data)
                    }, function (response) {
                        layer.msg("修改成功", {
                            "time": 1000
                        });
                        window.history.back();
                    });
                } else {
                    layer.msg("文件上传失败" + imdata.reson, {
                        "time": 1000
                    })
                }
            });
        } else {
            var arr = $("form").serializeArray();
            var data = {};
            for (var i = 0; i < arr.length; i++) {
                data[arr[i].name] = arr[i].value;
            };
            CertusFormAjax.ajax("toEditAsset", {
                "param": JSON.stringify(data)
            }, function (response) {
                layer.msg("修改成功", {
                    "time": 1000
                });
                window.history.back();
            });
        }

    })
}

function toAddAssets(CertusFormAjax, $scope) {
    CertusFormAjax.ajax("findAssStyles", {}, function (response) {
        $scope.data = response.data;
    });
    this.change = function () {
        CertusFormAjax.ajax("findAssStyle2s", {
            "code": $("#asname").val()
        }, function (response) {
            $scope.sdata = response.data;
        });
    };
    //所属公司
    CertusFormAjax.ajax("companyListByViewCode", {}, function (response) {
        $scope.comp = JSON.parse(response.data);
    });

    $(".submit").on('click', function () {
        if (!certusValidateNotnull()) {
            return;
        }

        var form = new FormData();
        var file = document.getElementById("pic").files[0];
        if (file != undefined) {
            form.append('file', file);
            CertusFormAjax.upload("fileUploadImg", form, function (response) {
                var imdata = response.data;
                if (imdata.isUpload == true) {
                    var arr = $("form").serializeArray();
                    var data = {};
                    for (var i = 0; i < arr.length; i++) {
                        data[arr[i].name] = arr[i].value;
                    };
                    data.picAddress = imdata.path;
                    CertusFormAjax.ajax("toAddAsset", {
                        "param": JSON.stringify(data)
                    }, function (response) {
                        layer.msg("录入成功", {
                            "time": 1000
                        });
                        window.history.back();
                    });
                } else {
                    layer.msg("文件上传失败" + data.reson, {
                        "time": 1000
                    })
                }
            });
        } else {
            var arr = $("form").serializeArray();
            var data = {};
            for (var i = 0; i < arr.length; i++) {
                data[arr[i].name] = arr[i].value;
            };
            CertusFormAjax.ajax("toAddAsset", {
                "param": JSON.stringify(data)
            }, function (response) {
                layer.msg("录入成功", {
                    "time": 1000
                });
                window.history.back();
            });
        }

    })
}

function editast(id) {
    id = id.replace(/#/g,"-");
    location.href = "#/toEditAsset/" + id;
}

function toEditAssets(CertusFormAjax, $scope, $routeParams) {
    var id = $routeParams.id.replace(/-/g,"#");
    //待办
    CertusFormAjax.ajax("toDelAssets", {
        "asid": id
    }, function (response) {
        var pfMap = response.data.pfMap;
        $scope.id = pfMap.id;
        $scope.assetId = pfMap.asset_id;
        $scope.proNo = pfMap.pro_no;
        $scope.assetName = pfMap.asset_name;
        $scope.assetStyle1 = pfMap.asset_cate1 + "->" + pfMap.asset_cate2 + "->" +
            pfMap.asset_style1 + "->" + pfMap.asset_style2;
        $scope.assetStatus = pfMap.asset_status;
        $scope.companyCode = pfMap.company;
        if (pfMap.asset_status == 0) {
            $scope.status = "占用";
        } else if (pfMap.asset_status == 1) {
            $scope.status = "维修";
        } else if (pfMap.asset_status == 2) {
            $scope.status = "停用";
        } else if (pfMap.asset_status == 3) {
            $scope.status = "报废";
        } else if (pfMap.asset_status == 4) {
            $scope.status = "待入库";
        } else if (pfMap.asset_status == 5) {
            $scope.status = "空闲";
        };
        $scope.address = pfMap.city_location + pfMap.building_location + pfMap.floor_location +
            pfMap.room_location + pfMap.area_location;
        $scope.owerName = pfMap.user_name;
        $scope.asource = pfMap.asset_source;
        $scope.assetProfile = pfMap.asset_profile;
        $scope.comments = pfMap.comments;
        $scope.purchaseTime = pfMap.purchaseTime;
        $scope.purchasePrice = pfMap.purchase_price;
        $scope.snNo = pfMap.sn_no;

        // 资产信息记录
        var astlogColumns = [{
            id: 'action_time',
            title: '操作时间',
            type: 'date',
            width: 100,
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'opUser',
            title: '操作人',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        }, {
            id: 'comments',
            title: '内容',
            type: 'string',
            columnClass: 'text-left',
        }];
        var astlogOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '资产信息记录',
            datas: response.data.hisMap,
            columns: astlogColumns,
            gridContainer: 'astlogContainer',
            toolbarContainer: 'astlogToolBarContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        var astlogGrid = $.fn.dlshouwen.grid.init(astlogOption);
        astlogGrid.load();
    });

    CertusFormAjax.ajax("isCrcd", {
        "code": "XMZCGL"
    }, function (response) {
        var data = JSON.parse(response.data);
        if (data.isTrue == true) {
            $scope.isCrud = true;
        } else {
            $scope.isCrud = false;
        }
    });
    //维护资产
    this.whAsset = function () {
        var astatus = $scope.assetStatus;
        if (astatus != 5) {
            layer.msg("当前资产未空闲，不能维修", {
                "time": 1000
            });
            return;
        }
        CertusFormAjax.ajax("toChageAsset", {
            "status": 1,
            "asId": $("#asId").val()
        }, function (response) {
            $scope.status = "维护";
            $scope.assetStatus = 1;
            layer.msg("已设置为维护资产", {
                "time": 1000
            });
        });
    }
    //报废资产
    this.bfAsset = function () {
        var astatus = $scope.assetStatus;
        if (astatus != 5) {
            layer.msg("当前资产未空闲，不能报废", {
                "time": 1000
            });
            return;
        }
        CertusFormAjax.ajax("toChageAsset", {
            "status": 3,
            "asId": $("#asId").val()
        }, function (response) {
            $scope.status = "报废";
            $scope.assetStatus = 3;
            layer.msg("已报废资产", {
                "time": 1000
            });
        });
    }
    //停用资产
    this.tyAsset = function () {
        var astatus = $scope.assetStatus;
        if (astatus != 5) {
            layer.msg("当前资产未空闲，不能停用", {
                "time": 1000
            });
            return;
        }
        CertusFormAjax.ajax("toChageAsset", {
            "status": 2,
            "asId": $("#asId").val()
        }, function (response) {
            $scope.status = "停用";
            $scope.assetStatus = 2;
            layer.msg("已停用资产", {
                "time": 1000
            });
        });
    }
    //启用资产
    this.qyAsset = function () {
        var astatus = $scope.assetStatus;
        if (astatus == 3 || astatus == 4 || astatus == 1 || astatus == 2) {
            CertusFormAjax.ajax("toChageAsset", {
                "status": 5,
                "asId": $("#asId").val()
            }, function () {
                $scope.status = "空闲";
                $scope.assetStatus = 5;
                layer.msg("已启用资产", {
                    "time": 1000
                });
            });
        } else {
            layer.msg("当前资产不能启用", {
                "time": 1000
            });
            return;
        }
    }

    this.showbox = function () {
        var astatus = $scope.assetStatus;
        if (astatus == 0 || astatus == 6 || astatus == 5) {
            $(".hidebox").show();
        } else {
            layer.msg("当前资产不能转移", {
                "time": 1000
            });
            return;
        }
    }

    //转移资产
    this.cgAsset = function () {
        var arr = {};
        arr.gsType = $("#gsType").val();
        var proId = $("#proId").val();
        var userId = $("#userId").val();
        var glUser = $("#userId1").val();
        if (!$("#gsPro").is(":hidden")){
            if (proId==""){
                layer.msg("请选择一个归属项目!");
                return;
            }
        }
        if (!$("#gsPeo").is(":hidden")){
            if (userId==""){
                layer.msg("请选择一个归属人!");
                return;
            }
        }
        if (!$("#gsKc").is(":hidden")){
            if (glUser==""){
                layer.msg("请选择一个资产管理员!");
                return;
            }
        }
        arr.proId = proId;
        arr.userId = userId;
        arr.glUser = glUser;
        arr.mdesc = $("#mdesc").val();
        arr.asId = $("#asId").val();
        CertusFormAjax.ajax("toMoveAsset", {
            "param": JSON.stringify(arr)
        }, function () {
            layer.msg("已转移资产", {
                "time": 1000
            });
            window.history.back();
        });
    }

    this.changeast = function () {
        var gsType = $("#gsType").val();
        if (gsType == 0) {
            $scope.showGsxm = false;
            $scope.showGsr = true;
            $scope.showKc = false;
            //个人
            CertusFormAjax.ajax("findSpUserList", {}, function (response) {
                var nhlTeams = [];
                var data = response.data;
                for (var i = 0; i < data.length; i++) {
                    var arr = {};
                    arr.name = data[i].userName + "[" + data[i].positonName + "]";
                    arr.id = data[i].userId;
                    nhlTeams.push(arr);
                }
                //自动补全
                var nhl = $.map(nhlTeams, function (obj) {
                    return {
                        value: obj.name,
                        data: {
                            category: obj.id
                        }
                    };
                });
                // Initialize autocomplete with local lookup:
                $('#autocomplete').devbridgeAutocomplete({
                    lookup: nhl,
                    minChars: 1,
                    onSelect: function (suggestion) {
                        $("#userId").val(suggestion.data.category);
                    },
                    showNoSuggestionNotice: true,
                    noSuggestionNotice: 'Sorry, no matching results'
                });
            });
        } else if (gsType==1){
            $scope.showGsxm = true;
            $scope.showGsr = false;
            $scope.showKc = false;
            CertusFormAjax.ajax("findSeProList", {}, function (response) {
                var nhlTeams = [];
                var data = response.data;
                for (var i = 0; i < data.length; i++) {
                    var arr = {};
                    arr.name = data[i].proName;
                    arr.id = data[i].id;
                    nhlTeams.push(arr);
                }
                //自动补全
                var nhl = $.map(nhlTeams, function (obj) {
                    return {
                        value: obj.name,
                        data: {
                            category: obj.id
                        }
                    };
                });
                // Initialize autocomplete with local lookup:
                $('#proName').devbridgeAutocomplete({
                    lookup: nhl,
                    minChars: 1,
                    onSelect: function (suggestion) {
                        $("#proId").val(suggestion.data.category);
                    },
                    showNoSuggestionNotice: true,
                    noSuggestionNotice: 'Sorry, no matching results'
                });
            });
        }else{
            $scope.showGsxm = false;
            $scope.showGsr = false;
            $scope.showKc = true;
            CertusFormAjax.ajax("findAssetUsers", {
            }, function (response) {
                $scope.zcUsers = response.data;
            })

        }
    }
    changeast();
}

function hidebox() {
    $(".hidebox").hide();
};
/**********项目的资产管理***********/
function findProAssets() {
    // 资产信息
    var assetsColumns = [{
        id: 'asset_id',
        title: '资产编号',
        width: 160,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'asset_style1',
        title: '资产类目',
        width: 110,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'astName',
        title: '资产类别',
        width: 120,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'Asset_Status',
        title: '目前状态',
        width: 73,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record) {
            var content = '';
            var status = record.asset_status;
            if (status == 0) {
                content += "占用";
            } else if (status == 1) {
                content += "维护";
            } else if (status == 2) {
                content += "停用";
            } else if (status == 3) {
                content += "报废";
            } else if (status == 4) {
                content += "待入库";
            } else if (status == 5) {
                content += "空闲";
            }
            return content;
        }
    }, {
        id: 'City_Location',
        title: '放置地点',
        width: 73,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'user_name',
        title: '归属者',
        width: 73,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'pro_name',
        title: '归属项目',
        width: 100,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'asset_source',
        title: '来源方式',
        width: 73,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'comments',
        title: '资产描述',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'operation',
        title: '操作',
        width: 70,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record) {
            var content = '';
            content += '<button class="btn btn-xs btn-success" onclick="toLkAssets(\'' + record.asset_id + '\');"><i class="fa fa-edit"></i>查看</button>';
            return content;
        }
    }];
    $CertusJsonAjax.dataInit("findAssetsList", {
        "code": 3,
        "param": proId
    }, assetsColumns, 'assetspContainer', 'assetspToolBarContainer');
}

function toLkAssets(id) {
    toLoadHtml(25, id);
};

function toDetail(id) {
    $certusUtils.ajax("toDelAssets", {
        "asid": id
    }, function (response) {
        var pfMap = response.data.pfMap;
        $("#assetId").html(pfMap.asset_id);
        $("#proNo").html(pfMap.pro_no);
        $("#assetStyle1").html(pfMap.asset_style1);
        $("#assetStyle2").html(pfMap.asset_style2);
        if (pfMap.asset_status == 0) {
            $("#status").html("占用");
        } else if (pfMap.asset_status == 1) {
            $("#status").html("维修");
        } else if (pfMap.asset_status == 2) {
            $("#status").html("停用");
        } else if (pfMap.asset_status == 3) {
            $("#status").html("报废");
        } else if (pfMap.asset_status == 4) {
            $("#status").html("待入库");
        } else if (pfMap.asset_status == 5) {
            $("#status").html("空闲");
        };
        $("#address").html(pfMap.city_location + pfMap.building_location + pfMap.floor_location +
            pfMap.room_location + pfMap.area_location);
        $("#owerName").html(pfMap.user_name);
        $("#asource").html(pfMap.asset_source);
        $("#comments").html(pfMap.comments);

        // 资产信息记录
        var astlogColumns = [{
            id: 'action_time',
            title: '操作时间',
            type: 'date',
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'opUser',
            title: '操作人',
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'comments',
            title: '内容',
            type: 'string',
            columnClass: 'text-center',
        }];
        var astlogOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '资产信息记录',
            datas: response.data.hisMap,
            columns: astlogColumns,
            gridContainer: 'astlogpContainer',
            toolbarContainer: 'astlogpToolBarContainer',
            tools: '',
            pageSize: 10,
            pageSizeLimit: [10, 15, 20]
        };
        var astlogGrid = $.fn.dlshouwen.grid.init(astlogOption);
        astlogGrid.load();
    })
};

function toBack() {
    toLoadHtml(26);
}